package com.xiyoufang.club.repository;

import com.xiyoufang.club.pojo.SystemConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public abstract interface SystemConfigRepository
  extends JpaRepository<SystemConfig, Integer>
{
  @Query(nativeQuery=true, value="SELECT * FROM system_config WHERE `key`=:key ")
  public abstract SystemConfig getSystemConfigByKey(@Param("key") String paramString);
  
  @Query(nativeQuery=true, value="SELECT * FROM system_config WHERE `group`=:group AND `key`=:key ")
  public abstract SystemConfig getSystemConfigByGroupAndKey(@Param("group") String paramString1, @Param("key") String paramString2);
  
  @Query(nativeQuery=true, value="SELECT * FROM system_config WHERE `group`=:group ")
  public abstract List<SystemConfig> findSystemConfigByGroup(@Param("group") String paramString);
  
  @Transactional
  @Modifying
  @Query(nativeQuery=true, value=" UPDATE `system_config` set `value` =:val  WHERE id=:id")
  public abstract int updateSystemConfigById(@Param("id") int paramInt1, @Param("val") int paramInt2);
  
  @Query(nativeQuery=true, value=" SELECT * from system_config t where t.key =:key LIMIT 1")
  public abstract SystemConfig getByKey(@Param("key") String paramString);
}
